package com.zhongxiangspace.controller;

import com.zhongxiangspace.entity.*;
import com.zhongxiangspace.entity.VO.QueryAnalyzerOffice;
import com.zhongxiangspace.service.CountyService;
import com.zhongxiangspace.service.HouseService;
import com.zhongxiangspace.service.OfficeBuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 楼盘详情 房源列表
 */
@Controller()
public class BuildingListController {
    @Autowired
    private HouseService houseService;
    @Autowired
    private CountyService countyService;
    @Autowired
    private OfficeBuildingService officeBuildingService;
    @GetMapping("lists/bu{id}")
    public  String detailsBu(Model model,@PathVariable("id")Integer id){
        Map<String, Object> map = new HashMap<>();
        OfficeBuildings office = this.officeBuildingService.queryOne(id);
        map.put("office", office);
        BuildingsAttribute buildingsAttribute = this.officeBuildingService.queryAttr(office.getBuilding_id());
        map.put("buildingsAttribute", buildingsAttribute);
        County county = this.countyService.queryOne(office.getCounty_id());
        map.put("county", county);
        County trade_area = this.countyService.queryOne(office.getTrade_area_id());
        map.put("trade_area", trade_area);
        //热门楼盘
        QueryAnalyzer buildingQueryAnalyzer = new QueryAnalyzer();
        buildingQueryAnalyzer.setShowCode(1);
        buildingQueryAnalyzer.setHotCode(1);
        List<Map<String,Object>> officeBuildingsList=this.officeBuildingService.queryOfficeBuilding(buildingQueryAnalyzer);
        map.put("officeBuildings", officeBuildingsList);
        //楼盘所属房源
        QueryAnalyzerOffice queryAnalyzerOffice=new QueryAnalyzerOffice();
        queryAnalyzerOffice.setBuilding_id(office.getBuilding_id());
        List<House> houseList=this.houseService.queryBHList(queryAnalyzerOffice);
        map.put("houseList",houseList);
        model.addAttribute("data",map);
        return "list/building_detail";
    }
}
